using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;

using SBPweb.Modules.Smartparts;

namespace SBPweb.Presentation.Windows.Forms.Controls
{
    public class ModalUserControl : UserControl, ISmartpart
    {
        private SBPweb.Modules.Modularity.IModule mParentModule;
        private Form mForm;

        /// <summary>
        /// Parent Form
        /// </summary>
        public new Form ParentForm
        {
            get
            {
                return mForm;
            }
        }

        #region ISmartpart Members

        /// <summary>
        /// Gets or sets the value indicatig whether the ISmartpart is displayed.
        /// </summary>
        public bool IsVisible
        {
            get
            {
                return Visible;
            }
            set
            {
                Visible = false;
            }
        }

        /// <summary>
        /// Gets or sets the value indicatig whether the ISmartpart can respond to user interaction.
        /// </summary>
        public bool IsEnabled
        {
            get
            {
                return Enabled;
            }
            set
            {
                Enabled = true;
            }
        }

        [EditorBrowsable(EditorBrowsableState.Never)]
        [Browsable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        [Bindable(false)]
        public bool IsModal
        {
            get 
            {
                return true;
            }
        }

        /// <summary>
        /// Parent module of this control. this can be null.
        /// </summary>
        public SBPweb.Modules.Modularity.IModule ParentModule
        {
            get 
            {
                return mParentModule;
            }
        }

        /// <summary>
        /// Occurs, when the IsVisible or Visible property changes.
        /// </summary>
        public new event EventHandler VisibleChanged
        {
            add
            {
                base.VisibleChanged += value;
            }
            remove
            {
                base.VisibleChanged -= value;
            }
        }

        /// <summary>
        /// Occurs, when the IsEnabled or Enabled property changes.
        /// </summary>
        public new event EventHandler EnabledChanged
        {
            add
            {
                base.EnabledChanged += value;
            }
            remove
            {
                base.EnabledChanged -= value;
            }
        }

        #endregion

        /// <summary>
        /// Occurs, when the parent module already has a visible ModalDockingUserControl
        /// </summary>
        public event EventHandler DisplayFailed;

        /// <summary>
        /// Modal UserControl
        /// </summary>
        /// <param name="parentModule">parent module</param>
        public ModalUserControl(SBPweb.Modules.Modularity.IModule parentModule)
        {
            mParentModule = parentModule;
            mForm = new Form();
            mForm.Controls.Add(this);
        }

        internal void FireDisplayFailedEvent()
        {
            if (DisplayFailed != null)
            {
                DisplayFailed(this, EventArgs.Empty);
            }
        }

    }
}
